//
//  AllDataVC.m
//  DefendHealth
//
//  Created by 吾诺瀚卓 on 17/3/8.
//  Copyright © 2017年 iMacOne. All rights reserved.
//

#import "AllDataVC.h"
#import "DailyRecordCell.h"
@interface AllDataVC ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *tableView;

@end

@implementation AllDataVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view addSubview:self.tableView];
  
}

-(UITableView *)tableView{
    
    
    if (!_tableView) {
        
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight, kScreenWidth, kScreenHeight-k_NavigationHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = k_TableBackColor;
        //[_tableView registerClass:[DailyRecordCell class] forCellReuseIdentifier:@"DailyRecordCell"];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.tableHeaderView = [self headerView];
        
    }
    
    return _tableView;
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 1;
            break;
        case 1:
            return 5;
            break;
            
        default:
            break;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return [DailyRecordCell cellForHeight:indexPath.section];
    //return 275.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //DailyRecordCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DailyRecordCell" forIndexPath:indexPath];
    
   
//    
    NSString * cellIdentif = [DailyRecordCell cellReuseID:indexPath.section];
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentif];
    
    if (!cell) {
        cell = [[NSClassFromString(cellIdentif) alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentif];
    }
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return section == 0 ? 10.f:65.f;
    
}


//- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
//    
//    return section == 0 ? nil :[self footBtn ];
//}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return section == 0 ? nil :[self cellHeaderView ];
    
}

-(UIView *)cellHeaderView{
    
    UIView *headerBgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 65)];
    headerBgView.backgroundColor = kWhiteColor;
    
    UILabel *titleL = [ReduceCode creatLabelWithFrame:CGRectMake(20, 17, 100, 20) title:@"记录详情" titleColor:UIColorFromRGB(0x333333) font:14 textAlignment:NSTextAlignmentLeft];
    [headerBgView addSubview:titleL];
    
    UILabel *smallL = [ReduceCode creatLabelWithFrame:CGRectMake(20, kMaxY(titleL.frame)+5, 100, 20) title:@"2月20日" titleColor:UIColorFromRGB(0x333333) font:12 textAlignment:NSTextAlignmentLeft];
    [headerBgView addSubview:smallL];

    [ToolUtil createLine:64 superView:headerBgView lift:10 width:kScreenWidth-20 hight:1 color:K_LineColor];
    
    return headerBgView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10.0f;
}

-(UIView *)headerView{
    
    self.TitleNav.text = @"所有运动数据";
    self.TitleNav.textColor = UIColorFromRGB(0x666666);
    [self.leftbutton setImage:IMAGE(@"nav_icon_back") forState:UIControlStateNormal];
    
    [self.rigltbutton setImage:IMAGE(@"nav_icon_more") forState:UIControlStateNormal];
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, k_NavigationHeight, kScreenHeight, 220)];
    headerView.backgroundColor = kWhiteColor;
    [self.view addSubview:headerView];
    
    [ToolUtil createLine:0 superView:headerView lift:0 width:kScreenWidth hight:2 color:UIColorFromRGB(0xf7f7f8)];
    
    UILabel *titNameL = [ReduceCode creatLabelWithFrame:CGRectMake(20, 30, 100, 30) title:@"全部数据" titleColor:UIColorFromRGB(0x333333) font:18 textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:titNameL];
    

    UILabel * consumptionL = [ReduceCode creatLabelWithFrame:CGRectMake(0, 160, kScreenWidth/3, 20) title:@"3110" titleColor:UIColorFromRGB(0x333333) font:16 textAlignment:NSTextAlignmentCenter];
    [headerView addSubview:consumptionL];
    
    UILabel * timeL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3, 160, kScreenWidth/3, 20) title:@"20" titleColor:UIColorFromRGB(0x333333) font:16 textAlignment:NSTextAlignmentCenter];
    [headerView addSubview:timeL];
    
    UILabel * numL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3*2, 160, kScreenWidth/3, 20) title:@"10" titleColor:UIColorFromRGB(0x333333) font:16 textAlignment:NSTextAlignmentCenter];
    [headerView addSubview:numL];
    
    
    NSArray * STR = @[@"燃烧/千卡",@"时长/分钟",@"累计次数"];
    for (int D = 0; D<3; D++) {
        UILabel * dayL = [ReduceCode creatLabelWithFrame:CGRectMake(kScreenWidth/3*D, kMaxY(timeL.frame)+5, kScreenWidth/3, 12) title:STR[D] titleColor:UIColorFromRGB(0x888888) font:12 textAlignment:NSTextAlignmentCenter];
        [headerView addSubview:dayL];
    }
    
    UILabel *bigL = [ReduceCode creatLabelWithFrame:CGRectMake(0, 60, kScreenWidth, 50) title:@"52.5" titleColor:UIColorFromRGB(0x333333) font:40 textAlignment:NSTextAlignmentCenter];
    [headerView addSubview:bigL];
    
    UILabel *smallL = [ReduceCode creatLabelWithFrame:CGRectMake(0, 110, kScreenWidth, 20) title:@"累计里程 / 公里" titleColor:UIColorFromRGB(0x888888) font:12 textAlignment:NSTextAlignmentCenter];
    [headerView addSubview:smallL];
    
    return headerView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
